/*
 * MySQL Cluster SNMP monitoring subagent
 * Copyright (C) 2011, Steven Ayre <steveayre@gmail.com>
 *
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is MySQL Cluster SNMP monitoring subagent
 *
 * The Initial Developer of the Original Code is
 * Steven Ayre <steveayre@gmail.com>
 * Portions created by the Initial Developer are Copyright (C)
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Steven Ayre <steveayre@gmail.com>
 *
 * common.h -- Common utility functions header
 *
 */

#include <pthread.h>
#include <string.h>
#include <errno.h>
#include <libdaemon/daemon.h>

pthread_mutex_t strerror_mutex = PTHREAD_MUTEX_INITIALIZER;

/* I could use strerror_r, but this isn't GNU specific and possibly faster on memory (pointers to error in table with no copy?) */
/* This mutex is fine, as long as this is the only place strerror is used */
void daemon_perror(int prio, const char* prefix)
{
	pthread_mutex_lock(&strerror_mutex);
	daemon_log(prio, "%s: %s", prefix, strerror(errno));
	pthread_mutex_unlock(&strerror_mutex);
}

